package com.gs.api.projects.shejiao.web;

import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService;
import com.gs.api.projects.shejiao.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author guoyunfei on 2021/10/10 15:48
 * @className PayNoticeController
 * @description TODO
 * @Version 1.0
 */

@ApiIgnore
@RestController
@RequestMapping("/notice/pay")
public class PayNoticeController {

    /**
     * 小程序支付
     */
    @Autowired
    private WxPayService wxMiniPayService;

    @Autowired
    private PayService payService;

    @RequestMapping("/order")
    public String submit(@RequestBody String xmlData) throws WxPayException {
        System.out.println(xmlData);
        WxPayOrderNotifyResult parseOrderNotifyResult = wxMiniPayService.parseOrderNotifyResult(xmlData);

        String payNo = parseOrderNotifyResult.getOutTradeNo();
        String bizPayNo = parseOrderNotifyResult.getTransactionId();
        String appid = parseOrderNotifyResult.getAppid();
        payService.paySuccess(payNo, bizPayNo,appid);
        String xml = "SUCCESS";
        return xml;

    }

}
